package com.alan.wifishare.presenter;

import com.alan.libapi.business.dao.CallbackListener;
import com.alan.libapi.model.business.WifiMonthProfit;
import com.alan.wifishare.app.GlobalField;
import com.alan.wifishare.view.iview.IVSHAWifiDetail;

import java.util.ArrayList;
import java.util.List;

/**
 * @className: SHAWifiDetailPS
 * @describtion: SHAWifiDetailPS
 * @author: AlanWang
 * @email: 850267876@qq.com
 * @time: 2016/4/27 19:43
 */
public class SHAWifiDetailPS {

    private IVSHAWifiDetail ivshaWifiDetail;
    private List<WifiMonthProfit> wifiMonthProfitList = new ArrayList<>();

    public SHAWifiDetailPS(IVSHAWifiDetail ivshaWifiDetail) {
        this.ivshaWifiDetail = ivshaWifiDetail;
    }

    public List<WifiMonthProfit> getWifiMonthProfitList() {
        return wifiMonthProfitList;
    }

    public void getWifiProfit(){

        int wifiId = ivshaWifiDetail.getWifiInfo().getWifiId();
        GlobalField.businessHttp.getMySpecifyWifiProfitList(GlobalField.userSession, wifiId, new CallbackListener<List<WifiMonthProfit>>() {
            @Override
            public void onSuccess(List<WifiMonthProfit> result) {
                wifiMonthProfitList = result;
                ivshaWifiDetail.showWifiProfit(getProfit(wifiMonthProfitList));
            }

            @Override
            public void onFailure(int errorCode, String msg) {
                ivshaWifiDetail.toastMsg(msg);
            }
        });
    }

    /**
     * 计算该wifi各月收益总和
     * @param wifiMonthProfitList
     * @return
     */
    private float getProfit(List<WifiMonthProfit> wifiMonthProfitList){
        float profit = 0.0f;
        for (WifiMonthProfit wifiMonthProfit : wifiMonthProfitList) {
            profit += wifiMonthProfit.getWifiProfit();
        }
        return profit;
    }
}
